import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import * as echarts from 'echarts'
import 'element-ui/lib/theme-chalk/index.css'
// 导入全局样式表
import './assets/css/global.css'
import request from './request/request'

// 富文本编辑器
import tinymce from 'tinymce'
Vue.prototype.$tinymce = tinymce

Vue.prototype.$http = request
Vue.prototype.$headers = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
  'Access-Control-Allow-Headers': 'Content-Type'
}
Vue.prototype.$domain = 'http://localhost:8080'

// 获取常量
request.get('/const').then((res) => {
  // console.log(res.data.const)
  Vue.prototype.$cv = res.data.const
})

Vue.prototype.$echarts = echarts
Vue.config.productionTip = false
Vue.use(ElementUI)

// 全局过滤器
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)

  // 格式化
  const y = dt.getFullYear()
  // padStart(2,'0')如果不够2位,前面补充0
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: (h) => h(App)
}).$mount('#app')
